package com.lsfb.duishangbaos.Utils;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.zgscwjm.lsfbbasetemplate.adapter.ViewHolder;

import java.util.List;

/**
 * Created by fukunaka on 2017/5/16.
 */

public abstract class MyCommonAdapter<E> extends BaseAdapter {

    final static private String Tag = "CommonAdapter";

    private Context context;
    private List<E> list = null;

    private int layoutId;

    public MyCommonAdapter(Context context, int layoutId, List<E> list) {
        this.context = context;
        this.list = list;
        this.layoutId = layoutId;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public E getItem(int position) {
        Log.d(Tag, "getItem:" + position);
        return (E) (list == null ? 0 : list.get(position));
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.d(Tag, "postion:"+position);

//        if (convertView==null) {
//         holder  = new ViewHolder(context, parent, layoutId, position);
//            convertView.setTag(holder);
//            convertView = holder.getmView();
//        }else {
//        ViewHolder holder = ViewHolder.getViewHolder(context,convertView,parent,layoutId,position);
        ViewHolder holder = new ViewHolder(context, parent, layoutId, position);

//        holder.setmView(LayoutInflater.from(context).inflate(layoutId, parent, false));

//        }
        convert(holder, getItem(position));
        return holder.getmView();
    }

    // public abstract void setData(List<E> data);

    public abstract void convert(ViewHolder holder, E model);

}
